<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Admin</title>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<style type="text/css"> 
<!--
body {
    font: 12px simsun, arial, helvetica, clean, sans-serif;
    text-align: center;
    margin: 5px
}
 
a {
 margin: 0 10px;
 color:#000;
}

a:hover {
 color:#090;
}

table{width:95%}
table th{width:60px}
td{padding:5px 5px;margin:0;vertical-align:top;text-align: left}
select,input,textarea{width:100%}

input,textarea,button,select {
    border: 1px solid #83B2C9;
    background: #f5f5f5;
}
input:focus,textarea:focus,button:hover,select:hover {
    border: 1px solid #305987;
    background: #e5e5e5;
}
-->
</style>
  </head>

  <body>
 
 <form method="post" target="_blank">
 <table>
  <tr><th>片名</th><td colspan="9"><input name="title" type="text" /></td></tr>
  <tr>
   <th>分类</th><td><select name="category" style="width:100px"></select></td>
   <th>导演</th><td><input name="director" type="text" autocomplete="off" style="width:200px" /></td>
   <th>年代</th><td><select name="period" style="width:100px"></select></td>
   <th>地区</th><td><select name="area" style="width:100px"></select></td>
  </tr>
  <tr>
   <th>主演</th><td colspan="9"><input name="actors" autocomplete="off" type="text" /></td>
  </tr>
  <tr><th>简介</th><td colspan="9"><textarea name="summary" rows="2" maxlength="220">##summary##</textarea></td></tr>
  <tr><th>内容</th><td colspan="9"><textarea name="content" rows="3">##content##</textarea></td></tr>
  <tr><th>QVOD</th><td colspan="9"><select multiple="multiple" size="6" name="qvod">
  </select></td></tr>
  <tr><th>BDHD</th><td colspan="9"><select multiple="multiple" size="6" name="bdhd">
  </select></td></tr>
  <tr><th>ED2K</th><td colspan="9"><select multiple="multiple" size="6" name="ed2k">
  </select></td></tr>
  <tr><th>海报</th><td colspan="9"><input name="theFile" type="file" /><input name="blobKey" type="hidden" /></td></tr>
  <tr><td colspan="10" style="text-align:right"><button type="submit" disabled="disabled">submit</button></td></tr>
 </table>
 
 </form>
<script type="text/javascript" >
(function($) {
 
 var action = window.location.protocol + "//" + window.location.host + "/admin.do";
 
 var title = null;
 var category = null;
 var area = null;
 var director = null;
 var summary = null;
 var period = null;
 var content = null;
 var actors_arr = null;
 var qvod_arr = null;
 var bdhd_arr = null;
 var ed2k_arr = null;
 var blobKey = null;
 
/*##server_code##*/
 
 var category_arr = ["剧情片","动作片","动画片","喜剧片","恐怖片","战争片","爱情片","科幻片","纪录片","战争片","综艺片","连续剧"];
 var area_arr = ["大陆","台湾","香港","欧美","韩国","法国","泰国","日本","新加坡","印度","合拍","其他"];
 
 $("input[name=title]").val(title);
 var $category = $("select[name=category]");
 var $area = $("select[name=area]");
 var $director = $("input[name=director]");
 var $actors = $("input[name=actors]");
 var $period = $("select[name=period]");
 var $qvod = $("select[name=qvod]");
 var $bdhd = $("select[name=bdhd]");
 var $ed2k = $("select[name=ed2k]");
 var $blobKey = $("input[name=blobKey]");
 
 $director.val(director);
 $blobKey.val(blobKey);
 
 for(var i in category_arr){
   var c = category_arr[i];
   $category.append("<option value='" + c + "'>" + c + "</option>");
 }
 $category.val(category);

 for(var i in area_arr){
   var a = area_arr[i];
   $area.append("<option value='" + a + "'>" + a + "</option>");
 }
 $area.val(area);
 
 var year = (new Date()).getFullYear();
 for(var y = year; y > 1930; y--){
  $period.append("<option value='" + y + "'>" + y + "</option>");
 }
 $period.val(period);

 if(category != null){
   $category.empty().append("<option value='" + category + "'>" + category + "</option>");
 }

 if(actors_arr instanceof Array){
    $actors.val(actors_arr.join(","));
    $("input[type=file]").attr("disabled","disabled");
    $("button[type=submit]").removeAttr("disabled");
	$("form").attr("action",action);
 }
 
 if(qvod_arr instanceof Array){
     for(var i in qvod_arr){
       var q = qvod_arr[i];
       $qvod.append("<option value='" + q + "'>" + q + "</option>");
     }
 }
 if(bdhd_arr instanceof Array){
     for(var i in bdhd_arr){
       var b = bdhd_arr[i];
       $bdhd.append("<option value='" + b + "'>" + b + "</option>");
     }
 }
 if(ed2k_arr instanceof Array){
     for(var i in ed2k_arr){
       var e = ed2k_arr[i];
       $ed2k.append("<option value='" + e + "'>" + e + "</option>");
     }
 }
 
 $.ajaxSetup({url: action});

 $("input[type='file']").change(function (){
  $.ajax({
   type: "GET",
   data: "type=UploadUrl",
   success: function(action){
    $("form").attr("action",action).attr("enctype","multipart/form-data");
    $("button[type='submit']").removeAttr("disabled");
   }
  });
 });

 $("input[name=actors]").dblclick(function(){
   var $this = $(this);
   $this.val($this.val().replace(/[ ]/g,"").replace(/\//g,","));
 });
 
 $("select[multiple]").dblclick(function(){
  if($(this).children().size()>0){
    if(confirm("您确认要删除选中的项吗？")){
        $(this).find('option:selected').remove();
    }
  }
 });

 $("select[multiple]").bind('contextmenu',function(){
  var $this = $(this); 
  var t = $this.attr("name");
  var v = window.prompt("请输入" + t + "地址",t + "://"); 
  if(v){
   v = decodeURIComponent(v).replace(/(^\s*)|(\s*$)/g, "").replace(/[\r\n]/g, "").replace(/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/g,"").replace("[]","");
   $this.append("<option value='" + v + "'>" + v + "</option>");
  }
  return false;
 });
 
 $("form").submit(function(){
  $("select[multiple]").children().each(function(){
   $(this).attr("selected","selected");
  });
  //return false;
 });
 
 //$('#submit').click(function(){$('#form').submit()});

})(jQuery);
</script>
  </body>
</html>